/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

export class TestJSClassWithGet {
    name = 'test';

    get name() {
        return this.name;
    }
}

export class TestJSClassWithSet {
    name = 'test';

    set name(str) {
        this.name = str;
    }
}

export class TestJSClassWithSetAndGet {
    name = 'test';

    set name(str) {
        this.name = str;
    }

    get name() {
        return this.name;
    }
}

export class TestJSClassWithSetRange {
    age = 123;

    set age(num) {
        if (typeof num == 'number' && num >= 0) {
            this.age = num;
        }
    }
}

export class SumClass {
    num1 = 123;
    num2 = 123;

    constructor(num1, num2) {
        this.num1 = num1;
        this.num2 = num2;
    }

    get sum() {
        return num1 + num2;
    }
}

export class JSMethodClass {
    age = 123;

    getAge() {
        return this.age;
    }

    setAge(num) {
        this.age = num;
    }
}

export class JSClassWithConstructor {
    num = 123;
    age = 123;

    constructor(num, age) {
        this.num = num;
        this.age = num;
    }
}

export class JSClassWithDefaultConstructor {
    num = 123;

    constructor(num = 2) {
        this.num = num;
    }
}

export class JSClassTestThis {
    name = 'test';

    getName() {
        return this;
    }
}

export function ThisFunctionTest(a) {
    if (this) {
        this.a = a;
        return this.a.name;
    } else {
        return 1;
    }
}

class JSTestClasses {
    a = 123;
    b = 'hello';

    getA() {
        return this.a;
    }

    static getB() {
        return this.b;
    }
}

export function foo(obj1, obj2) {
    return { ...obj1, ...obj2 };
}

export function foo1(obj1, obj2) {
    return [...obj1, ...obj2];
}
